package dryven.request.controller.paramtransform.baseimpl;

import java.lang.annotation.Annotation;
import java.util.Locale;

import dryven.annotations.Default;
import dryven.request.controller.paramtransform.ActionParameterFillCandidate;
import dryven.request.controller.paramtransform.ActionParameterTransformFeedback;
import dryven.request.controller.paramtransform.ActionParameterTransformationException;
import dryven.request.http.Request;

public class DefaultValueFiller implements ActionParameterFillCandidate {

	@Override
	public void apply(Class<?> type, Annotation[] annotations, Request reauest, ActionParameterTransformFeedback feedback) {
		if(type.equals(Integer.TYPE) || type.equals(Integer.class)) {
			feedback.setParameter(0);
		} else if(type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
			feedback.setParameter(false);
		} else if(type.equals(Short.TYPE) || type.equals(Short.class)) {
			feedback.setParameter((short)0);
		} else if(type.equals(Byte.TYPE) || type.equals(Byte.class)) {
			feedback.setParameter((byte)0);
		} else if(type.equals(Double.TYPE) || type.equals(Double.class)) {
			feedback.setParameter(0.0);
		} else if(type.equals(Float.TYPE) || type.equals(Float.class)) {
			feedback.setParameter(0.0f);
		} else if(type.equals(Long.TYPE) || type.equals(Long.class)) {
			feedback.setParameter(0l);
		} else {
			feedback.setParameter(null);
		}
	}

	@Override
	public boolean canApply(Class<?> type, Annotation[] annotations) {
		for (Annotation annotation : annotations) {
			if(annotation.annotationType().equals(Default.class)) {
				return true;
			}
		}
		return false;
	}

}
